// 加载中
const Loading = (params) => {
  wx.showLoading({
    ...params
  });
};

// 网络请求
const wxRequest = (params) => {
  Loading({
    title: '数据加载中',
    mask: true
  })
  return new Promise((resolve, reject) => {
    const baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'
    wx.request({
      ...params,
      url: baseUrl + params.url,
      success: (res) => {
        resolve(res);
      },
      fail: (err) => {
        reject(err);
      },
      complete: () => {
        wx.hideLoading();
      },
    });
  })
}

export {
  Loading,
  wxRequest
}